
#include <uimanager.h>
#include "document_manager.h"




struct _UIManagerPrivate {
	GtkActionGroup* action_group;
};

#define UI_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_UI_MANAGER, UIManagerPrivate))
enum  {
	UI_MANAGER_DUMMY_PROPERTY
};
static UIManager* ui_manager_instance = NULL;
static UIManager* ui_manager_construct (GType object_type);
static UIManager* ui_manager_new (void);
static void __lambda1 (GtkRecentChooserMenu* recent, UIManager* self);
static void ___lambda1_gtk_recent_chooser_item_activated (GtkRecentChooserMenu* _sender, gpointer self);
static inline void ui_manager_create_last_open_menu (UIManager* self);
static GObject * ui_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties);
static gpointer ui_manager_parent_class = NULL;
static void ui_manager_finalize (GObject* obj);
static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func);



static UIManager* ui_manager_construct (GType object_type) {
	UIManager * self;
	self = g_object_newv (object_type, 0, NULL);
	return self;
}


static UIManager* ui_manager_new (void) {
	return ui_manager_construct (TYPE_UI_MANAGER);
}


static void __lambda1 (GtkRecentChooserMenu* recent, UIManager* self) {
	GError * inner_error;
	char* _tmp0;
	char* _tmp1;
	g_return_if_fail (recent != NULL);
	inner_error = NULL;
	_tmp0 = g_filename_from_uri (gtk_recent_info_get_uri (gtk_recent_chooser_get_current_item ((GtkRecentChooser*) recent)), NULL, &inner_error);
	if (inner_error != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
		g_clear_error (&inner_error);
		return;
	}
	_tmp1 = NULL;
	document_manager_create (document_manager_get_instance (), _tmp1 = _tmp0);
	_tmp1 = (g_free (_tmp1), NULL);
}


static void ___lambda1_gtk_recent_chooser_item_activated (GtkRecentChooserMenu* _sender, gpointer self) {
	__lambda1 (_sender, self);
}


static inline void ui_manager_create_last_open_menu (UIManager* self) {
	GtkWidget* last_open_menu;
	g_return_if_fail (self != NULL);
	last_open_menu = gtk_ui_manager_get_widget ((GtkUIManager*) self, "/main_menu/file/file_last_open");
	if (last_open_menu != NULL) {
		GtkRecentFilter* text_filter;
		GtkRecentChooserMenu* recent_menu;
		text_filter = g_object_ref_sink (gtk_recent_filter_new ());
		gtk_recent_filter_add_mime_type (text_filter, "text/*");
		recent_menu = g_object_ref_sink ((GtkRecentChooserMenu*) gtk_recent_chooser_menu_new ());
		gtk_recent_chooser_add_filter ((GtkRecentChooser*) recent_menu, text_filter);
		gtk_recent_chooser_set_sort_type ((GtkRecentChooser*) recent_menu, GTK_RECENT_SORT_MRU);
		gtk_recent_chooser_set_show_not_found ((GtkRecentChooser*) recent_menu, FALSE);
		g_signal_connect ((GtkRecentChooser*) recent_menu, "item-activated", (GCallback) ___lambda1_gtk_recent_chooser_item_activated, self);
		gtk_menu_item_set_submenu ((GTK_MENU_ITEM (last_open_menu)), (GtkWidget*) recent_menu);
		(text_filter == NULL) ? NULL : (text_filter = (g_object_unref (text_filter), NULL));
		(recent_menu == NULL) ? NULL : (recent_menu = (g_object_unref (recent_menu), NULL));
	}
}


UIManager* ui_manager_get_instance (void) {
	UIManager* _tmp1;
	if (ui_manager_instance == NULL) {
		UIManager* _tmp0;
		_tmp0 = NULL;
		ui_manager_instance = (_tmp0 = ui_manager_new (), (ui_manager_instance == NULL) ? NULL : (ui_manager_instance = (g_object_unref (ui_manager_instance), NULL)), _tmp0);
	}
	_tmp1 = NULL;
	return (_tmp1 = ui_manager_instance, (_tmp1 == NULL) ? NULL : g_object_ref (_tmp1));
}


GtkAction* ui_manager_get_action (UIManager* self, const char* name) {
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (name != NULL, NULL);
	return gtk_action_group_get_action (self->priv->action_group, name);
}


void ui_manager_set_sensitive_doc_actions (UIManager* self, gboolean sensitive) {
	char** _tmp1;
	gint doc_actions_size;
	gint doc_actions_length1;
	char** _tmp0;
	char** doc_actions;
	g_return_if_fail (self != NULL);
	_tmp1 = NULL;
	_tmp0 = NULL;
	doc_actions = (_tmp1 = (_tmp0 = g_new0 (char*, 12 + 1), _tmp0[0] = g_strdup ("file_save"), _tmp0[1] = g_strdup ("file_save_as"), _tmp0[2] = g_strdup ("file_save_all"), _tmp0[3] = g_strdup ("file_close"), _tmp0[4] = g_strdup ("file_close_all"), _tmp0[5] = g_strdup ("edit_undo"), _tmp0[6] = g_strdup ("edit_redo"), _tmp0[7] = g_strdup ("edit_cut"), _tmp0[8] = g_strdup ("edit_copy"), _tmp0[9] = g_strdup ("edit_paste"), _tmp0[10] = g_strdup ("edit_delete"), _tmp0[11] = g_strdup ("edit_select_all"), _tmp0), doc_actions_length1 = 12, doc_actions_size = doc_actions_length1, _tmp1);
	/*Menu "plik"
	Menu "Edycja"
	Menu "Wyszukaj"
	  "search_find",  
	  "search_replace",
	  "search_goto_line"*/
	{
		char** doc_action_collection;
		int doc_action_collection_length1;
		int doc_action_it;
		doc_action_collection = doc_actions;
		doc_action_collection_length1 = doc_actions_length1;
		for (doc_action_it = 0; doc_action_it < doc_actions_length1; doc_action_it = doc_action_it + 1) {
			const char* _tmp2;
			char* doc_action;
			_tmp2 = NULL;
			doc_action = (_tmp2 = doc_action_collection[doc_action_it], (_tmp2 == NULL) ? NULL : g_strdup (_tmp2));
			{
				gtk_action_set_sensitive (ui_manager_get_action (self, doc_action), sensitive);
				doc_action = (g_free (doc_action), NULL);
			}
		}
	}
	doc_actions = (_vala_array_free (doc_actions, doc_actions_length1, (GDestroyNotify) g_free), NULL);
}


static GObject * ui_manager_constructor (GType type, guint n_construct_properties, GObjectConstructParam * construct_properties) {
	GObject * obj;
	UIManagerClass * klass;
	GObjectClass * parent_class;
	UIManager * self;
	GError * inner_error;
	klass = UI_MANAGER_CLASS (g_type_class_peek (TYPE_UI_MANAGER));
	parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
	obj = parent_class->constructor (type, n_construct_properties, construct_properties);
	self = UI_MANAGER (obj);
	inner_error = NULL;
	{
		{
			GtkAction* _tmp0;
			GtkAction* _tmp1;
			GtkAction* _tmp2;
			GtkAction* _tmp3;
			GtkAction* _tmp4;
			GtkAction* _tmp5;
			GtkAction* _tmp6;
			GtkAction* _tmp7;
			GtkAction* _tmp8;
			GtkAction* _tmp9;
			GtkAction* _tmp10;
			GtkAction* _tmp11;
			GtkAction* _tmp12;
			GtkAction* _tmp13;
			GtkAction* _tmp14;
			GtkAction* _tmp15;
			GtkAction* _tmp16;
			GtkAction* _tmp17;
			GtkAction* _tmp18;
			GtkAction* _tmp19;
			GtkAction* _tmp20;
			GtkAction* _tmp21;
			GtkAction* _tmp22;
			GtkAction* _tmp23;
			gtk_ui_manager_add_ui_from_file ((GtkUIManager*) self, "ui.xml", &inner_error);
			if (inner_error != NULL) {
				goto __catch0_g_error;
				goto __finally0;
			}
			gtk_ui_manager_insert_action_group ((GtkUIManager*) self, self->priv->action_group, 0);
			/*Tworzye akcje
			Menu "Plik"*/
			_tmp0 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp0 = gtk_action_new ("file", "_Plik", NULL, NULL), NULL);
			(_tmp0 == NULL) ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL));
			_tmp1 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp1 = gtk_action_new ("file_new", "Nowy", NULL, GTK_STOCK_NEW), "<ctrl>n");
			(_tmp1 == NULL) ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL));
			_tmp2 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp2 = gtk_action_new ("file_open", "Otwórz", NULL, GTK_STOCK_OPEN), "<ctrl>o");
			(_tmp2 == NULL) ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL));
			_tmp3 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp3 = gtk_action_new ("file_last_open", "Ostatnio otwierane", NULL, NULL), NULL);
			(_tmp3 == NULL) ? NULL : (_tmp3 = (g_object_unref (_tmp3), NULL));
			_tmp4 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp4 = gtk_action_new ("file_save", "Zapisz", NULL, GTK_STOCK_SAVE), "<ctrl>s");
			(_tmp4 == NULL) ? NULL : (_tmp4 = (g_object_unref (_tmp4), NULL));
			_tmp5 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp5 = gtk_action_new ("file_save_as", "Zapisz jako...", NULL, GTK_STOCK_SAVE_AS), NULL);
			(_tmp5 == NULL) ? NULL : (_tmp5 = (g_object_unref (_tmp5), NULL));
			_tmp6 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp6 = gtk_action_new ("file_save_all", "Zapisz wszystkie", NULL, NULL), "<shift><ctrl>s");
			(_tmp6 == NULL) ? NULL : (_tmp6 = (g_object_unref (_tmp6), NULL));
			_tmp7 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp7 = gtk_action_new ("file_close", "Zamknij", NULL, GTK_STOCK_CLOSE), "<ctrl>w");
			(_tmp7 == NULL) ? NULL : (_tmp7 = (g_object_unref (_tmp7), NULL));
			_tmp8 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp8 = gtk_action_new ("file_close_all", "Zamknij wszystkie", NULL, NULL), "<shift><ctrl>w");
			(_tmp8 == NULL) ? NULL : (_tmp8 = (g_object_unref (_tmp8), NULL));
			_tmp9 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp9 = gtk_action_new ("file_quit", "Zakończ", NULL, GTK_STOCK_QUIT), "<alt>F4");
			(_tmp9 == NULL) ? NULL : (_tmp9 = (g_object_unref (_tmp9), NULL));
			/*Menu "edycja"*/
			_tmp10 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp10 = gtk_action_new ("edit", "_Edycja", NULL, NULL), NULL);
			(_tmp10 == NULL) ? NULL : (_tmp10 = (g_object_unref (_tmp10), NULL));
			_tmp11 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp11 = gtk_action_new ("edit_undo", "Cofnij", NULL, GTK_STOCK_UNDO), "<ctrl>z");
			(_tmp11 == NULL) ? NULL : (_tmp11 = (g_object_unref (_tmp11), NULL));
			_tmp12 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp12 = gtk_action_new ("edit_redo", "Ponów", NULL, GTK_STOCK_REDO), "<shift><ctrl>z");
			(_tmp12 == NULL) ? NULL : (_tmp12 = (g_object_unref (_tmp12), NULL));
			_tmp13 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp13 = gtk_action_new ("edit_cut", "Wytnij", NULL, GTK_STOCK_CUT), NULL);
			(_tmp13 == NULL) ? NULL : (_tmp13 = (g_object_unref (_tmp13), NULL));
			_tmp14 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp14 = gtk_action_new ("edit_copy", "Skopiuj", NULL, GTK_STOCK_COPY), NULL);
			(_tmp14 == NULL) ? NULL : (_tmp14 = (g_object_unref (_tmp14), NULL));
			_tmp15 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp15 = gtk_action_new ("edit_paste", "Wklej", NULL, GTK_STOCK_PASTE), NULL);
			(_tmp15 == NULL) ? NULL : (_tmp15 = (g_object_unref (_tmp15), NULL));
			_tmp16 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp16 = gtk_action_new ("edit_delete", "Usuń", NULL, GTK_STOCK_DELETE), NULL);
			(_tmp16 == NULL) ? NULL : (_tmp16 = (g_object_unref (_tmp16), NULL));
			_tmp17 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp17 = gtk_action_new ("edit_select_all", "Zaznacz wszytsko", NULL, GTK_STOCK_SELECT_ALL), "<ctrl>a");
			(_tmp17 == NULL) ? NULL : (_tmp17 = (g_object_unref (_tmp17), NULL));
			/*Menu "wyszukaj"*/
			_tmp18 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp18 = gtk_action_new ("search", "Wy_szukiwanie", NULL, NULL), NULL);
			(_tmp18 == NULL) ? NULL : (_tmp18 = (g_object_unref (_tmp18), NULL));
			_tmp19 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp19 = gtk_action_new ("search_find", "Znajdź", NULL, GTK_STOCK_FIND), "<ctrl>f");
			(_tmp19 == NULL) ? NULL : (_tmp19 = (g_object_unref (_tmp19), NULL));
			gtk_action_set_sensitive (ui_manager_get_action (self, "search_find"), FALSE);
			_tmp20 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp20 = gtk_action_new ("search_find_next", "Znajdź następny", NULL, NULL), "<ctrl>g");
			(_tmp20 == NULL) ? NULL : (_tmp20 = (g_object_unref (_tmp20), NULL));
			gtk_action_set_sensitive (ui_manager_get_action (self, "search_find_next"), FALSE);
			_tmp21 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp21 = gtk_action_new ("search_find_prev", "Znajdź poprzedni", NULL, NULL), "<ctrl><shift>g");
			(_tmp21 == NULL) ? NULL : (_tmp21 = (g_object_unref (_tmp21), NULL));
			gtk_action_set_sensitive (ui_manager_get_action (self, "search_find_prev"), FALSE);
			_tmp22 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp22 = gtk_action_new ("search_replace", "Zamień", NULL, GTK_STOCK_FIND_AND_REPLACE), "<ctrl>h");
			(_tmp22 == NULL) ? NULL : (_tmp22 = (g_object_unref (_tmp22), NULL));
			gtk_action_set_sensitive (ui_manager_get_action (self, "search_replace"), FALSE);
			_tmp23 = NULL;
			gtk_action_group_add_action_with_accel (self->priv->action_group, _tmp23 = gtk_action_new ("search_goto_line", "Przejdź do wiersza", NULL, GTK_STOCK_JUMP_TO), "<ctrl>i");
			(_tmp23 == NULL) ? NULL : (_tmp23 = (g_object_unref (_tmp23), NULL));
			gtk_action_set_sensitive (ui_manager_get_action (self, "search_goto_line"), FALSE);
			ui_manager_create_last_open_menu (self);
		}
		goto __finally0;
		__catch0_g_error:
		{
			GError * err;
			err = inner_error;
			inner_error = NULL;
			{
				char* _tmp24;
				GtkMessageDialog* _tmp25;
				GtkMessageDialog* msg;
				/*Brak pliku z definicją UI*/
				_tmp24 = NULL;
				_tmp25 = NULL;
				msg = (_tmp25 = g_object_ref_sink ((GtkMessageDialog*) gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, _tmp24 = g_strconcat ("Failed to load UI\n", err->message, NULL), NULL)), _tmp24 = (g_free (_tmp24), NULL), _tmp25);
				gtk_dialog_run ((GtkDialog*) msg);
				gtk_object_destroy ((GtkObject*) msg);
				(err == NULL) ? NULL : (err = (g_error_free (err), NULL));
				(msg == NULL) ? NULL : (msg = (g_object_unref (msg), NULL));
			}
		}
		__finally0:
		if (inner_error != NULL) {
			g_critical ("file %s: line %d: uncaught error: %s", __FILE__, __LINE__, inner_error->message);
			g_clear_error (&inner_error);
		}
	}
	return obj;
}


static void ui_manager_class_init (UIManagerClass * klass) {
	ui_manager_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (UIManagerPrivate));
	G_OBJECT_CLASS (klass)->constructor = ui_manager_constructor;
	G_OBJECT_CLASS (klass)->finalize = ui_manager_finalize;
}


static void ui_manager_instance_init (UIManager * self) {
	self->priv = UI_MANAGER_GET_PRIVATE (self);
	self->priv->action_group = gtk_action_group_new ("main_action_group");
}


static void ui_manager_finalize (GObject* obj) {
	UIManager * self;
	self = UI_MANAGER (obj);
	(self->priv->action_group == NULL) ? NULL : (self->priv->action_group = (g_object_unref (self->priv->action_group), NULL));
	G_OBJECT_CLASS (ui_manager_parent_class)->finalize (obj);
}


GType ui_manager_get_type (void) {
	static GType ui_manager_type_id = 0;
	if (ui_manager_type_id == 0) {
		static const GTypeInfo g_define_type_info = { sizeof (UIManagerClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) ui_manager_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (UIManager), 0, (GInstanceInitFunc) ui_manager_instance_init, NULL };
		ui_manager_type_id = g_type_register_static (GTK_TYPE_UI_MANAGER, "UIManager", &g_define_type_info, 0);
	}
	return ui_manager_type_id;
}


static void _vala_array_free (gpointer array, gint array_length, GDestroyNotify destroy_func) {
	if ((array != NULL) && (destroy_func != NULL)) {
		int i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
	g_free (array);
}




